package cn.org.eshow.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
 * 商品表
 */
@Entity
@Table(name = "product")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Product extends BaseObject implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;//商品ID

    @Column(name = "add_time")
    private Date addTime = new Date();// 添加时间

    @Column(name = "update_time")
    private Date updateTime = new Date();// 更新时间

//    @Column
//    private String category;// 分类(productCategory肌理,呼吸砖,平批,弹涂,海苔壁)

    @Column
    private String name;// 商品名称

    @Column
    private String style;// 风格  (ShopDataVar)
    @Column
    private Integer age;// 年龄段（1,0-20   2,21-40  3,41-60）

    @Column
    private Double price = 0.00;// 价格

    @Column(name = "cost_price", length = 10)
    private Double costPrice = 0.00;// 成本价

    @Column(name = "market_price", length = 10)
    private Double marketPrice = 0.00;// 市场价

    @Column(name = "month_sales", length = 11)
    private Integer monthSales;// 月销量

    @Column(length = 400)
    private String img;//主图片

    @Column(name = "imgs", length = 800)
    private String imgs;//图片地址(逗号隔开)

    @Column
    private String description;//描述

    @Column
    private String content;//商品简介

    @Column
    private Integer count;//评论次数

    @Column(name = "favorite_size")
    private Integer favoriteSize;//收藏数

    @Column
    private Integer state = 1;//状态（1上架，0下架）

    @Column(name = "if_discount")
    private Boolean ifDiscount = Boolean.FALSE;// 是否限时打折

    @Column
    private Double discount = 0.00;// 折扣

    @JsonIgnore
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "promotion_id")
    private Promotion promotion;// 促销ID

    @Column(name = "good_comment", length = 11)
    private Integer goodComment;// 好评数

    @Column(name = "middle_comment", length = 11)
    private Integer middleComment;// 中评数

    @Column(name = "bad_comment", length = 11)
    private Integer badComment;// 差评数

    @Column(name = "product_tags", length = 100)
    private String productTags = "";// 商品标签

    @Column
    private Boolean enabled = Boolean.TRUE;//是否可用

    @JsonIgnore
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_category_id")
    private ProductCategory productCategory;// 商品分类ID

    @JsonIgnore
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "product")
    private Set<ProductItem> productItems = new HashSet<ProductItem>(0);

    public Product() {
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Date getAddTime() {
        return addTime;
    }

    public void setAddTime(Date addTime) {
        this.addTime = addTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getStyle() {
        return style;
    }

    public void setStyle(String style) {
        this.style = style;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Double getPrice() {
        return price;
    }

    public void setPrice(Double price) {
        this.price = price;
    }

    public Double getCostPrice() {
        return costPrice;
    }

    public void setCostPrice(Double costPrice) {
        this.costPrice = costPrice;
    }

    public Double getMarketPrice() {
        return marketPrice;
    }

    public void setMarketPrice(Double marketPrice) {
        this.marketPrice = marketPrice;
    }

    public Integer getMonthSales() {
        return monthSales;
    }

    public void setMonthSales(Integer monthSales) {
        this.monthSales = monthSales;
    }

    public String getImg() {
        return img;
    }

    public void setImg(String img) {
        this.img = img;
    }

    public String getImgs() {
        return imgs;
    }

    public void setImgs(String imgs) {
        this.imgs = imgs;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public Integer getFavoriteSize() {
        return favoriteSize;
    }

    public void setFavoriteSize(Integer favoriteSize) {
        this.favoriteSize = favoriteSize;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public Boolean getIfDiscount() {
        return ifDiscount;
    }

    public void setIfDiscount(Boolean ifDiscount) {
        this.ifDiscount = ifDiscount;
    }

    public Double getDiscount() {
        return discount;
    }

    public void setDiscount(Double discount) {
        this.discount = discount;
    }

    public Promotion getPromotion() {
        return promotion;
    }

    public void setPromotion(Promotion promotion) {
        this.promotion = promotion;
    }

    public Integer getGoodComment() {
        return goodComment;
    }

    public void setGoodComment(Integer goodComment) {
        this.goodComment = goodComment;
    }

    public Integer getMiddleComment() {
        return middleComment;
    }

    public void setMiddleComment(Integer middleComment) {
        this.middleComment = middleComment;
    }

    public Integer getBadComment() {
        return badComment;
    }

    public void setBadComment(Integer badComment) {
        this.badComment = badComment;
    }

    public String getProductTags() {
        return productTags;
    }

    public void setProductTags(String productTags) {
        this.productTags = productTags;
    }

    public Boolean getEnabled() {
        return enabled;
    }

    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }

//    public String getCategory() {
//        return category;
//    }
//
//    public void setCategory(String category) {
//        this.category = category;
//    }

    public ProductCategory getProductCategory() {
        return productCategory;
    }

    public void setProductCategory(ProductCategory productCategory) {
        this.productCategory = productCategory;
    }

    public Set<ProductItem> getProductItems() {
        return productItems;
    }

    public void setProductItems(Set<ProductItem> productItems) {
        this.productItems = productItems;
    }

    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (o == null || getClass() != o.getClass())
            return false;

        Product pojo = (Product) o;
        if (id != null ? !id.equals(pojo.id) : pojo.id != null)
            return false;
        if (addTime != null ? !addTime.equals(pojo.addTime) : pojo.addTime != null)
            return false;
        if (updateTime != null ? !updateTime.equals(pojo.updateTime) : pojo.updateTime != null)
            return false;
//        if (category != null ? !category.equals(pojo.category) : pojo.category != null)
//            return false;
        if (name != null ? !name.equals(pojo.name) : pojo.name != null)
            return false;
        if (style != null ? !style.equals(pojo.style) : pojo.style != null)
            return false;
        if (price != null ? !price.equals(pojo.price) : pojo.price != null)
            return false;
        if (monthSales != null ? !monthSales.equals(pojo.monthSales) : pojo.monthSales != null)
            return false;
        if (age != null ? !age.equals(pojo.age) : pojo.age != null)
            return false;
        if (img != null ? !img.equals(pojo.img) : pojo.img != null)
            return false;
        if (imgs != null ? !imgs.equals(pojo.imgs) : pojo.imgs != null)
            return false;
        if (count != null ? !count.equals(pojo.count) : pojo.count != null)
            return false;
        if (state != null ? !state.equals(pojo.state) : pojo.state != null)
            return false;
        if (ifDiscount != null ? !ifDiscount.equals(pojo.ifDiscount) : pojo.ifDiscount != null)
            return false;
        if (promotion != null ? !promotion.equals(pojo.promotion) : pojo.promotion != null)
            return false;
        if (enabled != null ? !enabled.equals(pojo.enabled) : pojo.enabled != null)
            return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = result + (id != null ? id.hashCode() : 0);
        result = 31 * result + (addTime != null ? addTime.hashCode() : 0);
        result = 31 * result + (updateTime != null ? updateTime.hashCode() : 0);
//        result = 31 * result + (category != null ? category.hashCode() : 0);
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + (style != null ? style.hashCode() : 0);
        result = 31 * result + (age != null ? age.hashCode() : 0);
        result = 31 * result + (price != null ? price.hashCode() : 0);
        result = 31 * result + (monthSales != null ? monthSales.hashCode() : 0);
        result = 31 * result + (img != null ? img.hashCode() : 0);
        result = 31 * result + (imgs != null ? imgs.hashCode() : 0);
        result = 31 * result + (count != null ? count.hashCode() : 0);
        result = 31 * result + (state != null ? state.hashCode() : 0);
        result = 31 * result + (ifDiscount != null ? ifDiscount.hashCode() : 0);
        result = 31 * result + (promotion != null ? promotion.hashCode() : 0);
        result = 31 * result + (enabled != null ? enabled.hashCode() : 0);
        return result;
    }

    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("id", this.id)
                .append("addTime", this.addTime)
                .append("updateTime", this.updateTime)
                .append("name", this.name)
//                .append("category", this.category)
                .append("age", this.age)
                .append("style", this.style)
                .append("marketPrice", this.marketPrice)
                .append("price", this.price)
                .append("monthSales", this.monthSales)
                .append("img", this.img)
                .append("imgs", this.imgs)
                .append("count", this.count)
                .append("state", this.state)
                .append("promotion", this.promotion)
                .append("enabled", this.enabled)
                .toString();
    }
}
